home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Programming / Programming Languages / Yerk 3.64 / Supplement / Unsupported / Utilities / Requires < prev    next >
Text File  |  1985-10-15  |  4KB  |  103 lines

  1. \ Requires
  2. \ A few utility words by Jay Scott, June 1985.
  3. \
  4. \ Original Neon™ code © Copyright 1985 Jay Scott
  5. \ Released October 1985 by Tom O'Brien
  6. \ For free public distribution (not to be sold)
  7. \ provided this notice is kept intact.
  8. \
  9.  
  10. \ In a source file "Source File" put:
  11. \
  12. \     Requires "This File"  \ if the source file needs thisFile loaded first
  13. \     Requires "That File"  \ if the source file needs thatFile loaded first
  14. \     Marker "Source File"  \ declare that "Source File" is loaded
  15. \
  16. \ "This File" (and all other required files) should start with the line
  17. \
  18. \     Marker "This File"
  19. \
  20. \ so that Requires can tell whether it has already been loaded.  Requires will
  21. \ load each file only if it can't find in the dictionary a marker with the
  22. \ same name as the file to be loaded.
  23. \
  24. \ If you reload a file with a marker, Marker will automatically forget
  25. \ the old one.  You can't have two copies of one file loaded at once.
  26. \
  27. \ "This File" and "That File" can require other files.
  28. \ Nesting can't go deeper than six files altogether, counting both
  29. \ // and Requires.
  30. \
  31. \ To explicitly forget a marker, use Forget" .
  32.  
  33.  
  34. \ Expects a search string at HERE & searches all the right vocabularies
  35. \ for it.  The search string can contain blanks and other obnoxious characters.
  36. \ This code is lifted from FIND in the nucleus.
  37. : findHere   ( -- false )               \ if not found
  38.              ( -- pfa lenbyte true )    \ if found
  39.     ufind dup 0= if                 \ what's UFIND? it always leaves 0...
  40.       drop
  41.       here context @ (find)         \ look in context vocab
  42.       dup 0= if                     \ if not there,
  43.         context current - if        \ and if current <> context,
  44.           drop here latest (find)   \ look in current vocab
  45.         then
  46.       then
  47.     then
  48.   ;
  49.  
  50.  
  51. : Requires   ( -- ; "fileName" )
  52.     new: loadFile       \ new file on the file stack
  53.     ascii " word                    \ read quoted string from input stream
  54.     here count name: topFile
  55.     findHere if                     \ file is already loaded, do nothing
  56.       2drop
  57.     else                            \ file isn't loaded, announce & load it
  58.       cr ." Requires " here count type
  59.       interpret: loadFile
  60.     then
  61.     remove: loadFile    \ remove the file from the file stack
  62.   ;
  63.  
  64.  
  65. \ Forgets a word, given its PFA.
  66. \ This code is lifted from the original forget.
  67. : (Forget)    ( pfa -- )
  68.     dup fence u< abort" can't forget in protected dictionary"
  69.     dup nfa -> dp
  70.     lfa @ current !
  71.   ;
  72.  
  73.  
  74. \ For forgetting words with spaces in their names, like markers for instance.
  75. : Forget"   ( -- ; "Name" )
  76.     definitions
  77.     ascii " word
  78.     findHere 0= abort" I can't find that word."
  79.     drop (Forget)
  80.   ;
  81.  
  82.  
  83. \ Creates words that may have embedded spaces in their names.
  84. \ It’s to be used to create words with the same names as their files.
  85. \ Also automatically forgets back if there's a word with the same name.
  86. : Marker   { \ oldHere -- ; "Name" }
  87.     definitions
  88.     ascii " word                  \ read "Name" from the input stream
  89.     findHere if                   \ if word already exists,
  90.       here -> oldHere
  91.       cr ." forgetting old version of " here count type
  92.       drop (Forget)               \ forget it
  93.       oldHere c@ here c!          \ make the old name's length correct
  94.     then
  95.     here 1 and if                 \ ensure even word boundary
  96.       0 c,
  97.     then
  98.     $ 80 s,                       \ allot the name field
  99.     latest ,                      \ make a link field
  100.     current !                     \ make it the start of the dictionary
  101.     ' null cfa ,                  \ make a CFA to do nothing
  102.   ;
  103.